package com.bestcem.xm.award.service.impl;

import cn.hutool.core.lang.Dict;
import com.bestcem.xm.award.config.FileConfig;
import com.bestcem.xm.award.constant.Constants;
import com.bestcem.xm.award.constant.RedisKeyConstant;
import com.bestcem.xm.award.controller.param.point.PointAwardWinListParam;
import com.bestcem.xm.award.dao.*;
import com.bestcem.xm.award.entity.pojo.*;
import com.bestcem.xm.award.enums.*;
import com.bestcem.xm.award.grpc.client.DeliverGrpcService;
import com.bestcem.xm.award.service.AwardSmsService;
import com.bestcem.xm.award.service.PointAwardDrawService;
import com.bestcem.xm.award.service.bo.point.BandPointDrawBO;
import com.bestcem.xm.award.service.bo.point.PointAwardStatisBO;
import com.bestcem.xm.award.service.bo.point.PointAwardWinListBO;
import com.bestcem.xm.award.service.dto.DeliverRpcDTO;
import com.bestcem.xm.award.service.dto.FileInfoDTO;
import com.bestcem.xm.award.service.dto.awardaward.UpdateAwardStatusDTO;
import com.bestcem.xm.award.service.dto.point.PointAwardWinListExportDTO;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.oss.enums.OssPathEnum;
import com.bestcem.xm.common.core.uitls.ExcelExportUtil;
import com.bestcem.xm.common.core.uitls.StringUtil;
import com.bestcem.xm.componet.filestorage.service.StorageService;
import com.bestcem.xm.componet.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.bestcem.xm.award.constant.PointAwardConstant.*;
import static com.bestcem.xm.award.constant.RedisKeyConstant.SMS_AUTH_CODE_PREFIX;

/**
 * 抽奖相关服务实现
 *
 * @author xa.zhang <xa.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/6/30 17:47
 */
@Slf4j
@Service
public class PointAwardDrawServiceImpl implements PointAwardDrawService {

    /**
     * 默认false,本地测试使用
     */
    @Value("${app.award.devTest:false}")
    private boolean devTest;

    @Resource
    private BandPointDao bandPointDao;
    @Resource
    private AwardPointRecordDao awardPointRecordDao;
    @Resource
    private AwardAwardDao awardDao;
    @Resource
    private AwardRequestDao requestDao;
    @Resource
    private DeliverGrpcService deliverGrpcService;
    @Resource
    private FileConfig fileConfig;
    /*@Resource
    private OssService ossService;*/
    @Resource
    private AwardDispatcher awardDispatcher;
    @Resource
    private AwardSmsService awardSmsService;
    @Resource
    private AwardPointStatsDao awardPointStatsDao;
    @Resource
    private RedisService redisService;
    @Autowired
    private StorageService storageService;

    /**
     * 测试使用
     *
     * @return
     */
    public boolean isDebug() {
        return devTest;
    }

    /**
     * 领取积分奖励
     * 1、校验参数是否经过验证码验证
     * 2、奖励状态
     * 3、requestId只能用一次
     *
     * @param requestId request表的id
     * @param awardId   award表的id
     * @param phone     手机号
     * @return 结果
     */
    @Override
    public ServiceResult<BandPointDrawBO> drawPointAward(String requestId, String awardId, String phone) {
        if (StringUtils.isAnyBlank(requestId, awardId, phone)) {
            return ServiceResult.fail("缺少必填参数requestId、awardId");
        }
        ServiceResult checkParamResult = awardSmsService.checkParamRight(awardId, requestId);
        if (!checkParamResult.isSuccess()) {
            return checkParamResult;
        }

        //查询激活中的奖励
        AwardAwardDO award = awardDao.findByAwardIdAndStatus(awardId, AwardStatusEnum.ACTIVE.getIndex());
        if (award == null) {
            return ServiceResult.fail(AwardErrorMsgEnum.AWARD_STOPPED.getMsg());
        }

        //预检查。品牌积分信息检查，验证码检查，请求id检查
        ServiceResult preCheckResult = preCheck(award, requestId, awardId, phone);
        if (!preCheckResult.isSuccess()) {
            return preCheckResult;
        }

        //判断 request表数据状态 是等待抽奖的状态，
        AwardRequestDO awardRequestDO = requestDao.findAndModify(requestId, AwardRequestStatusEnum.PASS, awardId, AwardRequestStatusEnum.SEQ);
        if (awardRequestDO == null) {
            return ServiceResult.fail("已领取过或者错误的请求id");
        }

        ServiceResult deliverResult = getDeliverRpcDTO(awardRequestDO);
        if (!deliverResult.isSuccess()) {
            return deliverResult;
        }
        DeliverRpcDTO deliver = (DeliverRpcDTO) deliverResult.getData();
        AwardPointRecordDO awardPointRecord = createPointAwardEntity(deliver, awardRequestDO, award);
        awardPointRecord.setPhone(phone);

        //检查单个帐号领取次数限制
        if (!checkPhoneLimit(award, phone)) {
            awardPointRecord.setAmount(0);
            awardPointRecord.setStatus(PointRecordStatusEnum.NOWIN.getIndex());
            awardPointRecord.setMessage(AwardRequestStatusEnum.PHONE_LIMIT.getName());

            int count = awardPointRecordDao.insertSelective(awardPointRecord);
            if (count != 1) {
                return ServiceResult.fail(DB_ERROR_MSG);
            }
            return ServiceResult.fail(AwardRequestStatusEnum.PHONE_LIMIT.getName());
        }

        //领取条件判断完毕，可以领取
        Integer sinPoint = award.getBandPoint().getSinPoint();
        Integer total = award.getBandPoint().getTotal();
        //领取次数不限制
        if (total == null) {
            return createWinResult(awardPointRecord, sinPoint, award);
        }
        //领取次数有限制
        else {
            return tryDraw(award, awardId, awardPointRecord, total, sinPoint);
        }
    }

    /**
     * 预检查。品牌积分信息检查，验证码检查，请求id检查
     *
     * @param award     奖励
     * @param requestId 请求id
     * @param awardId   奖励id
     * @param phone     手机号
     * @return 结果
     */
    private ServiceResult preCheck(AwardAwardDO award, String requestId, String awardId, String phone) {
        //设置品牌积分信息
        if (award.getBandPoint() == null || award.getBandPoint().getPointId() == null) {
            return ServiceResult.fail("奖励未设置品牌积分信息");
        }
        String bandPointId = award.getBandPoint().getPointId();
        BandPointDO bandPoint = bandPointDao.selectByPrimaryKey(bandPointId);
        if (bandPoint == null) {
            return ServiceResult.fail("未查找到品牌积分信息");
        }

        //检查是否通过验证码
        String smsCodeResultKey = SMS_AUTH_CODE_PREFIX + awardId + ":" + requestId + ":" + phone + ":result";
        if (!SMS_CODE_REDIS_RESULT_DATA.equals(redisService.getString(smsCodeResultKey))) {
            return ServiceResult.fail("刷新页面重新验证验证码");
        }

        //再次确认该requestId是否尝试领取过
        AwardPointRecordDO oldPointRecord = awardPointRecordDao.findOneByRequestId(requestId);
        if (oldPointRecord != null) {
            return ServiceResult.fail("请求id已领取过");
        }
        return ServiceResult.success();
    }

    /**
     * 领取次数有限制时，尝试领取积分奖励
     *
     * @param award            奖励
     * @param awardId          奖励id
     * @param awardPointRecord 记录
     * @param total            总数
     * @param sinPoint         单个
     * @return 结果
     */
    private ServiceResult tryDraw(AwardAwardDO award, String awardId, AwardPointRecordDO awardPointRecord, Integer total, Integer sinPoint) {
        String lockKey = String.format(RedisKeyConstant.AWARD_POINT_DRAW_LOCK, awardId);
        redisService.lock(lockKey);
        try {
            //先检测，是否可领取
            String waitRedisKey = String.format(RedisKeyConstant.AWARD_POINT_WAIT_COUNT, awardId);
            String waitCountStr = redisService.getString(waitRedisKey);
            //下面只是粗略恢复，不可强依赖 point award redis key has been deleted
            if (StringUtils.isBlank(waitCountStr) && award.getStatus() != null && award.getStatus().intValue() == AwardStatusEnum.ACTIVE.getIndex()) {
                Integer curCount = award.getCurCount();
                if (curCount == null) {
                    curCount = 0;
                }
                waitCountStr = "" + (total - curCount);
                redisService.set(String.format(RedisKeyConstant.AWARD_POINT_WAIT_COUNT, awardId), waitCountStr);
            }
            Integer oldWaitCount = Integer.valueOf(waitCountStr);
            if (oldWaitCount <= 0) {
                awardPointRecord.setMessage(AwardRequestStatusEnum.TOTAL.getName());
                return createNotWinResult(awardPointRecord, award);
            }
            //到这里，开始对redis key进行-1操作，开始领取
            Long newWaitCount = redisService.incr(waitRedisKey, -1);
            if (newWaitCount.intValue() >= 0) {
                if (newWaitCount.intValue() == 0) {
                    stopAward(newWaitCount.intValue(), award);
                }
                return createWinResult(awardPointRecord, sinPoint, award);
            } else {
                //如果奖励次数已达，且配置了可以提前结束，那么就可以停止
                stopAward(newWaitCount.intValue(), award);
                awardPointRecord.setMessage(AwardRequestStatusEnum.TOTAL.getName());
                return createNotWinResult(awardPointRecord, award);
            }
        } finally {
            redisService.unlock(lockKey);
        }
    }

    /**
     * 统计
     *
     * @param id 奖励id
     * @return 结果
     */
    @Override
    public ServiceResult<PointAwardStatisBO> stats(String id) {

        PointStatsCacheDO pointStatsCacheDO = awardPointStatsDao.selectByAwardId(id);

        PointAwardStatisDO pointAwardStatisDO = null;
        PointAwardStatisBO pointAwardStatisBO = new PointAwardStatisBO();
        //积分奖励先查是否统计过，如果已经统计过，那么直接取值,否则重新统计
        if (pointStatsCacheDO == null) {
            pointAwardStatisDO = awardPointRecordDao.getSendAmountAndCount(id);
            if (pointAwardStatisDO != null) {
                pointAwardStatisBO.setAmount(pointAwardStatisDO.getAmount());
                pointAwardStatisBO.setCount(pointAwardStatisDO.getCount());
                awardPointStatsDao.insert(id, pointAwardStatisDO.getCount(), pointAwardStatisDO.getAmount());
            } else {
                awardPointStatsDao.insert(id, Constants.ZERO, Constants.ZERO);
            }

        } else {
            pointAwardStatisBO.setAmount(pointStatsCacheDO.getAmount());
            pointAwardStatisBO.setCount(pointStatsCacheDO.getCount());
        }

        return ServiceResult.success(pointAwardStatisBO);
    }

    /**
     * 查询列表
     *
     * @param param 条件
     * @return 结果
     */
    @Override
    public ServiceResult<PointAwardWinListBO> lists(PointAwardWinListParam param) {
        if (param.getPage() == null) {
            param.setPage(DEFAULT_PAGE);
        }
        if (param.getSize() == null) {
            param.setSize(DEFAULT_PAGE_SIZE);
        }

        long total = awardPointRecordDao.countByParam(param);
        List<AwardPointRecordDO> list = awardPointRecordDao.findListByParam(param);

        PointAwardWinListBO pointAwardWinListBO = new PointAwardWinListBO();
        List<PointAwardWinListBO.PointAwardWin> pointAwardWinList = new ArrayList<>();

        if (list == null || list.size() == 0) {
            pointAwardWinListBO.setTotal(0L);
            pointAwardWinListBO.setRows(pointAwardWinList);
            return ServiceResult.success(pointAwardWinListBO);
        }

        //参数转换
        for (AwardPointRecordDO awardPointRecord : list) {
            PointAwardWinListBO.PointAwardWin pointAwardWin = new PointAwardWinListBO.PointAwardWin();
            if (awardPointRecord == null) {
                continue;
            }
            BeanUtils.copyProperties(awardPointRecord, pointAwardWin);

            pointAwardWin.setDeliverChannelName(AwardEnumHelper.DeliverSourceEnumMap.get(awardPointRecord.getDeliverChannel()));
            pointAwardWin.setStatusStr(AwardEnumHelper.PointRecordStatusEnumMap.get(awardPointRecord.getStatus()));
            if (awardPointRecord.getSendTime() != null) {
                pointAwardWin.setSendTimeStr(cn.hutool.core.date.DateUtil.format(awardPointRecord.getSendTime(),
                        Constants.DATE_PATTERN));
            }

            pointAwardWinList.add(pointAwardWin);
        }

        pointAwardWinListBO.setTotal(total);
        pointAwardWinListBO.setRows(pointAwardWinList);
        return ServiceResult.success(pointAwardWinListBO);
    }

    /**
     * 导出
     *
     * @param param 条件
     * @return 结果
     */
    @Override
    public ServiceResult<FileInfoDTO> export(PointAwardWinListParam param) {
        AwardAwardDO award = awardDao.findById(param.getAwardId());
        if (Objects.isNull(award)) {
            return ServiceResult.fail("奖励不存在");
        }
        param.setPage(1);
        param.setSize(EXPORT_PAGE_SIZE);
        //获取总条数
        long total = awardPointRecordDao.countByParam(param);

        if (total == 0) {
            return ServiceResult.fail("当前表单没有可导出数据");
        }

        long allPage = total / EXPORT_PAGE_SIZE + 1;

        List<AwardPointRecordDO> allSrcList = new ArrayList<>();
        //分页查询
        for (int curPage = 1; curPage <= allPage; curPage++) {
            param.setPage(curPage);

            List<AwardPointRecordDO> list = awardPointRecordDao.findListByParam(param);
            if (list != null) {
                allSrcList.addAll(list);
            }
        }

        //参数转换
        List<PointAwardWinListExportDTO.PointAwardWinDTO> allList = new ArrayList<>();
        for (AwardPointRecordDO awardPointRecord : allSrcList) {
            PointAwardWinListExportDTO.PointAwardWinDTO pointAwardWinDTO = new PointAwardWinListExportDTO.PointAwardWinDTO();
            if (awardPointRecord == null) {
                continue;
            }
            BeanUtils.copyProperties(awardPointRecord, pointAwardWinDTO);
            pointAwardWinDTO.setDeliverChannelName(AwardEnumHelper.DeliverSourceEnumMap.get(awardPointRecord.getDeliverChannel()));
            pointAwardWinDTO.setStatusStr(AwardEnumHelper.PointRecordStatusEnumMap.get(awardPointRecord.getStatus()));

            if (awardPointRecord.getSendTime() != null) {
                pointAwardWinDTO.setSendTimeStr(cn.hutool.core.date.DateUtil.format(awardPointRecord.getSendTime(),
                        Constants.DATE_PATTERN));
            }

            allList.add(pointAwardWinDTO);
        }
        allSrcList.clear();

        //开始导出

        String awardName = award.getName();
        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String fileName = awardName + "_中奖名单_" + date + ".xlsx";
        // 生成Excel数据
        File excelFile = ExcelExportUtil.createExcelStream(allList, PointAwardWinListExportDTO.PointAwardWinDTO.class, fileConfig.getTempFilePath());
        //String url = ossService.uploadTempFile(excelFile, fileName, OssPathEnum.TEMP_AWARD, Constants.OSS_TEMP_EXPIRE_SECOND, null, "中奖明细导出");
        String url = storageService.upload(excelFile, fileName, OssPathEnum.TEMP_AWARD.getPath(), new Dict()).getUrl();
        if (Objects.nonNull(excelFile)) {
            excelFile.delete();
        }
        if (log.isInfoEnabled()) {
            log.info("url:{}", url);
        }

        return ServiceResult.success(new FileInfoDTO("", fileName, url));
    }

    /**
     * 根据请求信息，查询deliver信息
     *
     * @param awardRequestDO
     * @return
     */
    private ServiceResult getDeliverRpcDTO(AwardRequestDO awardRequestDO) {
        //查找信息，填充到AwardPointRecord
        DeliverRpcDTO deliver = null;
        if (isDebug()) {
            deliver = new DeliverRpcDTO();
            deliver.setChannel(DeliverSourceEnum.QRCODE.getIndex());
            deliver.setName("test deliever name");
        } else {
            if (awardRequestDO.getDeliver() == null || awardRequestDO.getDeliver().get(DELIVER_ID) == null) {
                return ServiceResult.fail("数据库缺少必要投放数据");
            }
            String deliverId = String.valueOf(awardRequestDO.getDeliver().get(DELIVER_ID));
            deliver = deliverGrpcService.getDeliverDto(deliverId);
        }
        if (deliver == null) {
            return ServiceResult.fail("deliver not found");
        }
        return ServiceResult.success(deliver);
    }

    /**
     * 创建未中奖返回
     *
     * @param awardPointRecord 记录
     * @param award            奖励
     * @return 结果
     */
    private ServiceResult createNotWinResult(AwardPointRecordDO awardPointRecord, AwardAwardDO award) {
        awardPointRecord.setAmount(0);
        awardPointRecord.setStatus(PointRecordStatusEnum.NOWIN.getIndex());
        int count = awardPointRecordDao.insertSelective(awardPointRecord);
        if (count != 1) {
            return ServiceResult.fail(DB_ERROR_MSG);
        }
        BandPointDrawBO bandPointDrawBO = new BandPointDrawBO();
        bandPointDrawBO.setAmount(null);

        if (award.getBasic() != null) {
            bandPointDrawBO.setDisplayLogoId(award.getBasic().getDisplayLogoId());
            bandPointDrawBO.setDisplayLogoPath(award.getBasic().getDisplayLogoPath());
            bandPointDrawBO.setDisplayName(award.getBasic().getDisplayName());
        }

        return ServiceResult.fail(bandPointDrawBO, "未发奖");
    }

    /**
     * 创建中奖返回
     *
     * @param awardPointRecord 记录
     * @param sinPoint         单个积分奖励
     * @param award            奖励
     * @return 结果
     */
    private ServiceResult createWinResult(AwardPointRecordDO awardPointRecord, Integer sinPoint, AwardAwardDO award) {
        awardPointRecord.setAmount(sinPoint);
        awardPointRecord.setStatus(PointRecordStatusEnum.WIN.getIndex());
        int count = awardPointRecordDao.insertSelective(awardPointRecord);
        if (count != 1) {
            return ServiceResult.fail(DB_ERROR_MSG);
        }

        //品牌积分奖励，暂时不发送通知，只更新curCount
        int modifyCount = awardDao.updateCurCountAddOneById(awardPointRecord.getAwardId());
        if (modifyCount != 1) {
            log.error("更新失败");
        }

        //统计数量
        awardPointStatsDao.addCountAndAmountByAwardId(awardPointRecord.getAwardId(), Constants.INT1, sinPoint);

        BandPointDrawBO bandPointDrawBO = new BandPointDrawBO();
        bandPointDrawBO.setAmount(sinPoint);

        if (award.getBasic() != null) {
            bandPointDrawBO.setDisplayLogoId(award.getBasic().getDisplayLogoId());
            bandPointDrawBO.setDisplayLogoPath(award.getBasic().getDisplayLogoPath());
            bandPointDrawBO.setDisplayName(award.getBasic().getDisplayName());
        }
        return ServiceResult.success(bandPointDrawBO);
    }

    /**
     * 领取积分时，单个手机号领取次数限制
     *
     * @param award 奖励
     * @param phone 手机号
     * @return 结果
     */
    boolean checkPhoneLimit(AwardAwardDO award, String phone) {
        //红包单个帐号领取次数限制
        AwardAwardDO.Rule rule = award.getRule();
        if (rule != null && rule.getAccount() != null) {
            long count = awardPointRecordDao.countByIdAndPhoneAndNotPass(award.getId(), phone);
            if (count >= rule.getAccount()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 如果奖励次数已达，且配置了可以提前结束，那么就可以停止
     *
     * @param count 剩余可领取次数
     * @param award 奖励
     */
    private void stopAward(Integer count, AwardAwardDO award) {
        if (count == null || count > 0) {
            return;
        }
        if (award != null && award.getBandPoint() != null && award.getBandPoint().getStopAdvance()) {
            // 结束奖励
            UpdateAwardStatusDTO updateAwardStatusDTO = new UpdateAwardStatusDTO();
            updateAwardStatusDTO.setAwardId(award.getId());
            updateAwardStatusDTO.setStatus(AwardStatusEnum.FINISH.getIndex());
            updateAwardStatusDTO.setOldStatus(award.getStatus());
            updateAwardStatusDTO.setOrgId(award.getOrgId());
            ServiceResult<String> result = awardDispatcher.updateAwardStatus(updateAwardStatusDTO);
            if (log.isInfoEnabled()) {
                log.info("awardId:{},奖励结束结果:{},msg:{}", award.getId(), result.getErrorCode(), result.getMsg());
            }
        }
    }

    /**
     * 创建默认积分奖励记录实体
     *
     * @param deliver        投放信息
     * @param awardRequestDO 请求信息
     * @param award          奖励信息
     * @return 记录
     */
    @Override
    public AwardPointRecordDO createPointAwardEntity(DeliverRpcDTO deliver, AwardRequestDO awardRequestDO, AwardAwardDO award) {

        AwardPointRecordDO awardPointRecord = new AwardPointRecordDO();
        awardPointRecord.setRecordId(StringUtil.getId());
        //设置deliver信息
        awardPointRecord.setDeliverChannel(deliver.getChannel());

        String deliverId = null;
        Map map = awardRequestDO.getDeliver();
        if (map.get(DELIVER_ID) != null) {
            deliverId = "" + map.get(DELIVER_ID);
        }
        awardPointRecord.setDeliverId(deliverId);
        awardPointRecord.setDeliverName(deliver.getName());

        awardPointRecord.setAwardId(award.getId());
        awardPointRecord.setRequestId(awardRequestDO.getId());
        awardPointRecord.setStatus(PointRecordStatusEnum.PASS.getIndex());

        awardPointRecord.setSeq(Long.valueOf(awardRequestDO.getSurvey().getSeq()));

        //设置品牌积分信息。品牌积分信息新建后就无法修改
        awardPointRecord.setPointId(award.getBandPoint().getPointId());
        awardPointRecord.setPointName(award.getBandPoint().getPointName());
        awardPointRecord.setPointCode(award.getBandPoint().getCode());

        awardPointRecord.setAwardId(award.getId());
        Date now = new Date();
        awardPointRecord.setCreateTime(now);
        awardPointRecord.setUpdateTime(now);
        awardPointRecord.setSendTime(now);

        awardPointRecord.setRemark(award.getBandPoint().getRemark());

        return awardPointRecord;

    }

    /**
     * 插入失败记录
     *
     * @param awardRequestDO 请求信息
     * @param award          奖励信息
     * @param errorMsg       错误信息
     * @return 结果
     */
    @Override
    public ServiceResult insertFailRecord(AwardRequestDO awardRequestDO, AwardAwardDO award, String errorMsg) {
        ServiceResult deliverResult = getDeliverRpcDTO(awardRequestDO);
        if (!deliverResult.isSuccess()) {
            return deliverResult;
        }
        DeliverRpcDTO deliver = (DeliverRpcDTO) deliverResult.getData();
        AwardPointRecordDO awardPointRecord = createPointAwardEntity(deliver, awardRequestDO, award);
        awardPointRecord.setPhone("");
        awardPointRecord.setAmount(0);
        awardPointRecord.setStatus(PointRecordStatusEnum.NOWIN.getIndex());
        awardPointRecord.setMessage(errorMsg);
        int count = awardPointRecordDao.insertSelective(awardPointRecord);
        if (count != 1) {
            return ServiceResult.fail(DB_ERROR_MSG);
        }
        return ServiceResult.success();
    }

    /**
     * 检查是否还有领取次数，粗略检查。在实际领取时会再次检查
     *
     * @param award 奖励信息
     * @return
     */
    @Override
    public boolean checkWaitCount(AwardAwardDO award) {
        if (award == null || award.getBandPoint() == null) {
            return false;
        }
        //未限制总次数
        if (award.getBandPoint().getTotal() == null) {
            return true;
        }
        //先检测，是否可领取
        String waitRedisKey = String.format(RedisKeyConstant.AWARD_POINT_WAIT_COUNT, award.getId());
        String waitCountStr = redisService.getString(waitRedisKey);
        if (StringUtils.isBlank(waitCountStr) && award.getBandPoint().getTotal() > 0) {
            return true;
        }
        if (Integer.valueOf(waitCountStr).intValue() > 0) {
            return true;
        }
        return false;
    }

}